﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using WinFormsApp1.Common;

namespace WinFormsApp1.Leo.ListWeeks03
{
    public partial class SaleDisliteAdd : Form
    {
        public SaleDisliteAdd()
        {
            InitializeComponent();
            GetClents();
        }

        //商品代号
        public async void GetClents()
        {
            var items = await HttpClientHelper.RequestUrl<string, ApiResult<List<UPCClients>>>(URLCommon.Url2, "/WeekListOne_Leo/GetClientsShow", HttpClientHelper.MethodType.GET, default);

            uiComboBox1.DataSource = items.Data;
            uiComboBox1.DisplayMember = "CustomerNickname";
            uiComboBox1.ValueMember = "CustomerId";
        }

        public class UPCClients
        {
            public int CustomerId { get; set; }
            public string CustomerNickname { get; set; }
        }

        public record SaleDiss(DateTime SalesDetailsDate, int CustomerId, string SalesDetailsOrderNumber, string SalesDetailsOrderNum, bool SalesDetailsState, bool IsDelete);

        private async void uiButton1_Click(object sender, EventArgs e)
        {
            var SalesDetailsDate = Convert.ToDateTime(uiDatePicker1.Text);
            var CustomerId = Convert.ToInt32(uiComboBox1.SelectedValue);
            var SalesDetailsOrderNumber = uiTextBox1.Text;
            var SalesDetailsOrderNum = uiTextBox2.Text;
            var SalesDetailsState = true;
            var IsDelete = false;



            SaleDiss saleDiss = new(SalesDetailsDate, CustomerId, SalesDetailsOrderNumber, SalesDetailsOrderNum, SalesDetailsState, IsDelete);
            var res = await HttpClientHelper.RequestUrl<SaleDiss, ApiResult<SaleDis>>(URLCommon.Url1, "/WorkList01_leo/GetSaleDetaisAdd", HttpClientHelper.MethodType.POST, saleDiss);
            if (res.Code == 1)
            {
                MessageBox.Show("添加成功");
            }
        }

        public class SaleDis
        {

            /// <summary>
            /// 发货日期
            /// </summary>
            public DateTime SalesDetailsDate { get; set; }

            /// <summary>
            /// 客户名称
            /// </summary>
            public int CustomerId { get; set; }

            /// <summary>
            /// 订货件数
            /// </summary>
            public string SalesDetailsOrderNumber { get; set; }

            /// <summary>
            /// 订货数量
            /// </summary>
            public string SalesDetailsOrderNum { get; set; }

            /// <summary>
            /// 订单状态
            /// </summary>
            public bool SalesDetailsState { get; set; }

            /// <summary>
            /// 是否删除
            /// </summary>
            public bool IsDelete { get; set; } = false;
        }


    }
}
